import { UserStorageKey, UserTokenKey, UserOppenId, UserStartTime, UserEndTime  } from '../../static/libs/config.js'
export default {
	state: {
		userInfo: uni.getStorageSync(UserStorageKey) ||  {},
		forcedLogin : true,//是否需要强制登录
		defaultAvatar : '../../static/img/common/avatar.jpg',
		token: uni.getStorageSync(UserTokenKey) ||  '',
		oppenid: uni.getStorageSync(UserOppenId) ||  '',
		startTime: uni.getStorageSync(UserStartTime) ||  '',
		endTime: uni.getStorageSync(UserEndTime) ||  '',
		
		
	},
	mutations: {
		setUserInfo(state, userinfo) {
			state.userInfo = userinfo;
			uni.setStorageSync(UserStorageKey,userinfo)
		},
		clearUserInfo(state) {
			state.userInfo = {};
			uni.removeStorageSync(UserStorageKey)
		},
		setToken(state,token) {
			state.token = token;
			uni.setStorageSync(UserTokenKey, token);
		},
		clearToken(state) {
			state.token = '';
			uni.removeStorageSync(UserTokenKey)
		},
		setOppenId(state,oppenid) {
			state.oppenid = oppenid;
			uni.setStorageSync(UserOppenId, oppenid);
		},
		clearOppenId(state) {
			state.oppenid = '';
			uni.removeStorageSync(UserOppenId)
		},
		setStartTime(state,startTime) {
			state.startTime = startTime;
			uni.setStorageSync(UserStartTime, startTime);
		},
		clearStartTime(state) {
			state.startTime = '';
			uni.removeStorageSync(UserStartTime)
		},
		setEndTime(state,endTime) {
			state.endTime = endTime;
			uni.setStorageSync(UserEndTime, endTime);
		},
		clearEndTime(state) {
			state.endTime = '';
			uni.removeStorageSync(UserEndTime)
		},
	},
	actions: {
		handSetToken({ commit },token){
			commit('setToken',token);
		},
		handSetUserInfo({ commit },obj){
			commit('setUserInfo',obj);
		},
		handSetOppenId({ commit },obj){
			commit('setOppenId',obj);
		},
		handSetStartTime({ commit },obj){
			commit('setStartTime',obj);
		},	
		handSetEndTime({ commit },obj){
			commit('setEndTime',obj);
		},
		handClearUserInfo({ commit }){
			commit('clearUserInfo');
			commit('clearToken');
			commit('clearOppenId');
			commit('clearStartTime');
			commit('clearEndTime');
		},
		// type 1 手机号认证  2 实名认证
		noBindModal({state},type){
			let userInfo = state.userInfo
			if(type == 1){
				if(!userInfo.phone){
					return true;
				}
			}else if(type == 2){
				let nameFlag = userInfo.cert_status == 0 ? true : userInfo.cert_status;
				return nameFlag;
			}
			return false;
		}
	}
}
